package com.jeff.tianti.controller;

import com.jeff.tianti.cms.entity.Job;
import com.jeff.tianti.cms.entity.JobResumeMiddle;
import com.jeff.tianti.cms.entity.Resume;
import com.jeff.tianti.cms.service.JobResumeMiddleService;
import com.jeff.tianti.cms.service.JobService;
import com.jeff.tianti.cms.service.ResumeService;
import com.jeff.tianti.common.dto.AjaxResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/job/resume")
public class JobResMiddleController {
    @Autowired
    private JobResumeMiddleService jobResMiddleService;
    @Autowired
    private JobService jobService;
    @Autowired
    private ResumeService resumeService;

    /**
     * @Ceator:liuYI
     * @Describe:人才天地职位申请提交
     */
    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public AjaxResult saveJobResumeMiddle(@RequestParam("jobId") String jobId, @RequestParam("resumeId") String resumeId) {
        if (StringUtils.isBlank(jobId)) {
            throw new RuntimeException("jobId:参数为空");
        }
        if (StringUtils.isBlank(resumeId)) {
            throw new RuntimeException("resumeId:参数为空");
        }
        List<JobResumeMiddle> jobResumeMiddles = jobResMiddleService.findByResumeIdAndJobId(resumeId, jobId);
        if (CollectionUtils.isEmpty(jobResumeMiddles)) {
            JobResumeMiddle jobResumeMiddle = new JobResumeMiddle();
            jobResumeMiddle.setJobId(jobId);
            jobResumeMiddle.setResumeId(resumeId);
            jobResumeMiddle.setCreateDate(new Date());
            Resume resume = resumeService.find(resumeId);
            jobResumeMiddle.setUid(resume.getUid());
            jobResMiddleService.save(jobResumeMiddle);
        }
        return AjaxResult.setSuccessData(null);
    }

}
